#include "halio.h"
#include "main.h"
#include <stdint.h>
#include "stm32f405xx.h"

/// @brief 基于 stm32f405RG 的 GPIO 引脚操作
/// @param pin 
/// @param value 
void halIoWrite(uint8_t pin, uint8_t value)
{
    GPIO_TypeDef *GPIOx = (GPIO_TypeDef *)(GPIOA_BASE + 0x040UL * ((pin & 0xF0) - 0xA0));
    uint16_t pinBit = (uint16_t)(0x0001 << (pin & 0x0F));

    HAL_GPIO_WritePin(GPIOx, pinBit, (GPIO_PinState)value);
}

/// @brief 基于 stm32f405RG 的 GPIO 引脚操作
/// @param pin 
/// @return 
uint8_t halIoRead(uint8_t pin)
{
    GPIO_TypeDef *GPIOx = (GPIO_TypeDef *)(GPIOA_BASE + 0x040UL * ((pin & 0xF0) - 0xA0));
    uint16_t pinBit = (uint16_t)(0x0001 << (pin & 0x0F));

    return (uint8_t)HAL_GPIO_ReadPin(GPIOx, pinBit);
}
